'''
    该案例演示元祖 tuple
'''
# 创建元祖
# 元祖只包含一个元素的时候,需要在元祖后面添加逗号,否则括号会被当作运算符使用
# tuple2 = (100,)  # 100 如果不加逗号,就是一个int
# print(tuple2)
# tuple1 = (10, 20, 30,40,50)
# print(tuple1)

# 使用元组推导式,创建元组
# tup_gen = (i * 2 for i in range(10))
# print(tup_gen)  #<generator object <genexpr> at 0x0000026FAD70C2B0>
# tup2 =tuple(tup_gen)
# print(tup2)    #(0, 2, 4, 6, 8, 10, 12, 14, 16, 18)


# 访问元祖
# tup1 = (1, 2, 3,4,5,6)
# print(tup1[-2])
# print(tup1[0:-2])

# 元祖相加
# tup1 =(100,200,300)
# tup2 = ("a","b","v")
# print(tup1 + tup2)

# 元祖相乘
# tup1 =(100,200,300)
# print(tup1 * 2)

# 检查元素是否存在元祖中
# tuple1 = (1, 2, 3)
# print(1 in tuple1)

# 获取元祖的长度
# tuple1 = (1, 2, 3)
# print(len(tuple1))

# 求元祖中元素的最大值和最小值,求和
# tuple1 = (1, 2, 3)
# print(max(tuple1))
# print(min(tuple1))
# print(sum(tuple1))

# 遍历元祖
tuple1 = (10, 20, 30,40,50)
# for item in tuple1:
#     print(item)

# for index,item in enumerate(tuple1):
#     print(index,item)

for i in range(len(tuple1)):
    print(tuple1[i])

# 元组的不可变指的是元组所指向的内存中的内容不可变，但可以重新赋值。
# tuple1 = (100, 200, 300)
# print(id(tuple1), tuple1)
# tuple1 = tuple1 + (1, 2, 3)
# print(id(tuple1), tuple1)

tuple5 = (10, 20, 30,40,[1,2,3])
tuple5[-1].append(4)
print(tuple5)